<?php
namespace Admin\Model;
use Think\Model;
class GoodsModel extends Model{
  function imgUpload($config,$key){
    $file = $_FILES["$key"];
    if($file['error']==0){
      $upload = new \Think\Upload($config);
      $img = new \Think\Image();
      $pic = $upload->upload();
      //dump($pic);
      $pic_ori = $config['rootPath'] . $pic["$key"]['savepath'] . $pic["$key"]['savename'];
      //dump($pic_ori);
      $pic_sma = $config['rootPath'] . $pic["$key"]['savepath'] . 'small' . $pic["$key"]['savename'];
      $img->open($pic_ori);
      $img->Thumb(200,200);
      $img->save($pic_sma);
      $pic = array(
        'goods_pic' =>$pic_ori,
        'goods_small_pic' =>$pic_sma
      );
      return $pic;
    }else{
      return false;
    }
  }
  function imgAllUpload($config,$key,$goods_id){
      //dump($_FILES);
      $upload = new \Think\Upload($config);
      $img = new \Think\Image();
      $pic = $upload->upload();
      //$pic = $upload->getError();
      // dump($pic);
      // die;
      //dump($pic);
      $arr = array();
      foreach($pic as $key=>$v){
        $pic_ori = $config['rootPath'] . $v['savepath'] . $v['savename'];
        $pic_big = $config['rootPath'] . $v['savepath'] . 'big' . $v['savename'];
        $pic_mid = $config['rootPath'] . $v['savepath'] . 'mid' . $v['savename'];
        $pic_sma = $config['rootPath'] . $v['savepath'] . 'sma' . $v['savename'];
        $img->open($pic_ori);
        $img->Thumb(800,800);
        $img->save($pic_big);
        $img->open($pic_ori);
        $img->Thumb(350,350);
        $img->save($pic_mid);
        $img->open($pic_ori);
        $img->Thumb(50,50);   
        $img->save($pic_big);
        $arr[] = array(
          'goods_id' =>$goods_id,
          'pic_orin' =>$pic_ori,
          'pic_big'  =>$pic_big,
          'pic_mid' =>$pic_mid,
          'pic_sma' =>$pic_sma
        );
        //dump($arr);
      }
    return $arr;
  }
}
?>
